In [8]:
import numpy as np
import matplotlib.pyplot as plt
import itertools
import math
In [1]:
import re

tournaments = []

with open("tournaments8.txt", "r") as f:
    for line in f:
        graph, count = line.strip().rsplit(None, 1)
        count = int(count)
        graph_flat = [int(edge) for edge in re.sub(r"[^01 ]", "", graph).split()]
        graph = [graph_flat[i*8:(i+1)*8] for i in range(8)]
        assert(f"{graph} {count}" == line.strip())
        tournaments.append((graph, count))
In [14]:
from collections import Counter
counts_in = Counter()
counts_out = Counter()
for graph, _count in tournaments:
    in_degrees = [0] * 8
    out_degrees = [0] * 8
    for u in range(8):
        in_degree = 0
        out_degree = 0
        for v in range(8):
            if u == v:
                continue
            if graph[u][v]:
                out_degree += 1
            else:
                in_degree += 1
        in_degrees[in_degree] += 1
        out_degrees[out_degree] += 1
    counts_in[tuple(in_degrees)] += 1
    counts_out[tuple(out_degrees)] += 1
fig, axs = plt.subplots(1, 2, figsize=(8, 4))
axs[0].plot(sorted(counts_in.values()))
axs[1].plot(sorted(counts_out.values()))
fig.show(warn=False)
In [18]:
from collections import Counter
counts_out = Counter()
for graph, _count in tournaments:
    in_degrees = [0] * 8
    out_degrees = [0] * 8
    for u in range(8):
        in_degree = 0
        out_degree = 0
        for v in range(8):
            if u == v:
                continue
            if graph[u][v]:
                out_degree += 1
            else:
                in_degree += 1
        in_degrees[u] = in_degree
        out_degrees[v] = out_degree
    out = Counter()
    for u in range(8):
        for v in range(8):
            if graph[u][v]:
                out[(out_degrees[u], out_degrees[v])] += 1
    counts_out[frozenset(out.items())] += 1

fig, ax = plt.subplots()
ax.plot(sorted(counts_out.values()))
fig.show(warn=False)
In [36]:
# https://en.wikipedia.org/wiki/Laplacian_matrix
adj_matrices = [np.array(graph) for graph, count in tournaments]
degrees = []
for matrix in adj_matrices:
    degrees.append(np.diagflat(np.array([np.sum(matrix[i]) for i in range(8)])))
laplacians = [degree - adj for degree, adj in zip(degrees, adj_matrices)]
In [70]:
X = []
Y = []
blues = []
for laplacian in laplacians:
    vals = np.linalg.eigvals(laplacian)
    vals.sort()
    blues.append(vals[3].real)
min_blue = min(blues)
max_blue = max(blues)

fig, ax = plt.subplots(dpi=300)
for laplacian in laplacians:
    vals = np.linalg.eigvals(laplacian)
    vals.sort()
    gray = (vals[3] - min_blue) / (max_blue - min_blue)
    ax.plot(vals[1].real, vals[2].real, ',', color=(1 - gray, 0, gray))
fig.show(warn=False)